package my.avoskagae.client.presenter;

import my.avoskagae.client.eventbus.MainBus;
import my.avoskagae.client.view.IMainView;
import my.avoskagae.client.view.gwt.MainView;
import my.avoskagae.service.rpc.client.AuthUserServiceAsync;
import my.avoskagae.utils.UserInfo;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.inject.Inject;
import com.mvp4g.client.annotation.Presenter;
import com.mvp4g.client.presenter.BasePresenter;

@Presenter(view = MainView.class)
public class MainPresenter extends BasePresenter<IMainView, MainBus>  implements IMainPresenter{
	
	@Inject
	AuthUserServiceAsync authUserService;
	
	public void onStart(){
		authUserService.getUserInfo(GWT.getHostPageBaseURL(), new AsyncCallback<UserInfo>() {
			
			@Override
			public void onSuccess(UserInfo result) {
				view.setUserInfo(result);
			}
			
			@Override
			public void onFailure(Throwable caught) {
			}
		});
		
		eventBus.showCatalog();
	}
	
	public void onSetMainList(IsWidget mainList){
		view.setMainList(mainList);
	}
	
	public void onSetDetail(IsWidget mainList){
		view.setDetail(mainList);
	}
	
	@Override
	public void refresh() {
		//TODO переписать отображение и обновление каталога нормально
		eventBus.showCatalog();
		
	}

}
